<template>
  <div class="create-product-attr-range">
    <el-form ref="form" :model="productAttrRange" :rules="rules" label-width="100px" size="small">
      <el-form-item label="属性值" prop="rangeValue">
        <el-input v-model="productAttrRange.rangeValue" auto-complete="off"></el-input>
      </el-form-item>
      <el-form-item label="描述" prop="remarks">
        <el-input v-model="productAttrRange.remarks" auto-complete="off"></el-input>
      </el-form-item>
    </el-form>
    <div class="operate-button">
      <el-button @click="handleCancel" size="small">取 消</el-button>
      <el-button type="primary" @click="handleConfirm" size="small">确 定</el-button>
    </div>
  </div>
</template>
<script>
import { createProductAttrRange } from "@/api/product";

export default {
  name: "CreateProductAttrRange",
  props: {
    code: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      productAttrRange: {
        rangeValue: "",
        remarks: ""
      },
      rules: {
        rangeValue: [
          { required: true, message: "请输入属性值", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.productAttrRange.specCode = this.code
  },
  methods: {
    handleCancel() {
      this.$emit("after-create", false);
    },
    handleConfirm() {
      this.$refs.form.validate(valid => {
        if (valid) {
          createProductAttrRange(this.productAttrRange).then(response => {
            this.$message({
              message: "新建成功",
              type: "success",
              duration: 1000
            });
            this.$emit("after-create", true);
          });
        }
      });
    }
  }
};
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
.create-product-attr-range {
  .el-form-item {
    width: 90%;
  }
}
.operate-button {
  text-align: center;
}
</style>


